﻿
app.controller('CheckFormController', function ($scope, $http, $window, $compile, $filter, ipCookie, common, option, Upload) {
    $scope.result = {};
    $scope.dateOption = option.date;
    $scope.datetimeOption = option.datetime;


    ////////////////////////////////////////////////////////////监督检查//////////////////////////////////////////////
	$scope.InitLxImgUpload = function (id, optionId, index) {
        try {
            var id = id + optionId + "_" + index;
            lx.media.chooseImage({
                count: 1,
                sourceType: ["album", "camera"],
                quality: 'high',
                success: function (res) {
                    var filelist = res.tempFiles;
                    var img = document.getElementById(id);
                    img.src = filelist[0].base64;
                    var file = $scope.base64ToFile(filelist[0].base64, filelist[0].name);
                    Upload.upload({
                        method: 'POST',
                        url: '../CheckForm/UploadImage',
                        file: file
                    }).success(function (ret) {
                        common.success($scope, null, ret);
                        if (ret.Code == 100) {
							
                            var fileobj = {};
                            fileobj.OptionId = optionId;
                            fileobj.FileId = ret.Data;
                            fileobj.Index = index;
                            for (var z = 0; z < $scope.FileList.length; z++) {
                                var f = $scope.FileList[z];
                                if (f.OptionId == optionId && f.Index == index) {
                                    $scope.FileList.splice($.inArray(f, $scope.FileList, 1));
                                }
                            }
                            $scope.FileList.push(fileobj);
                        }
                        else {
                            mui.toast(ret.Msg);
                        }
                    })
                }
            });
        } catch (error) {
            mui.toast(error);
        }
    }
    $scope.base64ToFile = function (base64str, filename) {
        try {
            const arr = base64str.split(',');
            const mimeType = arr[0].match(/:(.*?);/)[1]; // 获取 MIME 类型
            var byteCharacters = atob(arr[1]);
            var byteArrays = [];
            for (var offset = 0; offset < byteCharacters.length; offset += 1024) {
                var slice = byteCharacters.slice(offset, offset + 1024);
                var byteNumbers = new Array(slice.length);
                for (var i = 0; i < slice.length; i++) {
                    byteNumbers[i] = slice.charCodeAt(i);
                }
                var byteArray = new Uint8Array(byteNumbers);
                byteArrays.push(byteArray);
            }
            var file = new Blob(byteArrays, { type: mimeType });
            file.lastModifiedDate = new Date();
            file.name = filename;
            return file;
        } catch (error) {
            mui.toast(error);
        }
    }
	
    $scope.ScanAddPlace = function () {
        if ($scope.PlaceList.length > 0) {
            mui.toast("请先保存当前检查场所");
            return false;
        }
        $scope.FileList = [];
        lx.device.scanCode({
            type: ["qrCode", "barCode"],
            success: function (res) {
                var place = JSON.parse(result.result);
                if (place.placeId != null && place.roomId != null && place.placeName != null) {
                    $http({
                        method: 'POST',
                        url: '../CheckForm/GetPlaceCheckDetailInfo',
                        data: { 'PlaceId': place.placeId, 'CheckType': $scope.AddModel.CheckType },
                    }).success(function (ret) {
                        common.success($scope, null, ret);
                        if (ret.Code == 100) {
                            if (ret.Data.CheckOptionList != null) {
                                for (var i = 0; i < ret.Data.CheckOptionList.length; i++) {
                                    ret.Data.CheckOptionList[i]["Result"] = 1;
                                }
                                setTimeout(function () {
                                    for (var x = 0; x < ret.Data.CheckOptionList.length; x++) {
                                        var data = ret.Data.CheckOptionList[x];
                                        for (var i = 0; i < $scope.ImageCount.length; i++) {
                                            var imagebox = "#imagebox-" + data.OptionId + "_" + $scope.ImageCount[i];
                                            var dragImgUpload = new DragImgUpload(imagebox, {
                                                callback: function (files, optionId, index) {
                                                    //回调函数，可以传递给后台等等
                                                    var file = files[0];
                                                    Upload.upload({
                                                        method: 'POST',
                                                        url: '../CheckForm/UploadImage',
                                                        file: file
                                                    })
                                                        .success(function (r) {
                                                            $scope.Submiting = false;
                                                            if (r.Code == 100) {
                                                                var fileobj = {};
                                                                fileobj.OptionId = optionId;
                                                                fileobj.FileId = r.Data;
                                                                fileobj.Index = index;
                                                                for (var z = 0; z < $scope.FileList.length; z++) {
                                                                    var f = $scope.FileList[z];
                                                                    if (f.OptionId == optionId && f.Index == index) {
                                                                        $scope.FileList.splice($.inArray(f, $scope.FileList, 1));
                                                                    }
                                                                }
                                                                $scope.FileList.push(fileobj);
                                                                console.log($scope.FileList);

                                                            } else
                                                                alertify.alert(r.Msg);
                                                        })
                                                        .error(function (data, status, headers, config) {
                                                            common.error($scope);
                                                            alertify.alert("请检查网络");
                                                        })
                                                }
                                            }, data.OptionId, $scope.ImageCount[i]);
                                        }
                                    }
                                }, 1000);
                            }

                            $scope.PlaceList.push(ret.Data);
                        }
                        else {
                            mui.toast(ret.Msg);
                        }
                    })
                }
            },
            fail: function (err) {
                mui.toast(JSON.stringify(err));
            }
        });
        //var result = {
        //    "result": "{\"placeId\":1,\"roomId\":3,\"placeName\":\"龙华10kV变电站\"}"
        //};

    }

    $scope.ScanPlaceCode = function () {
        lx.device.scanCode({
            type: ["qrCode", "barCode"],
            success: function (res) {
                var place = JSON.parse(res.result);
                if (place.placeId != null && place.roomId != null) {
                    $scope.PlaceId = place.placeId;
                    $scope.PlaceName = place.placeName;
                    $scope.RoomId = place.roomId;
                    $scope.AddModel.RoomId = place.roomId;
                    $scope.GetPlaceDepartment($scope.PlaceId, $scope.AddModel);
                    $http({
                        method: 'POST',
                        url: '../CheckForm/GetMyCheckTypeList',
                        data: { 'PlaceId': $scope.PlaceId }
                    }).success(function (ret) {
                        if (ret.Data != null) {
                            $scope.AddModel.CheckType = ret.Data.Id + '';
                        }

                        if ($scope.AddModel.CheckType != null) {
                            $scope.GetCheckItemList($scope.RoomId, $scope.AddModel.CheckType);
                        }
                    })
                        .error(function (data, status, headers, config) {
                            if ($scope.AddModel.CheckType != null) {
                                $scope.GetCheckItemList($scope.RoomId, $scope.AddModel.CheckType);
                            }
                        });


                }
            },
            fail: function (err) {
                mui.toast(JSON.stringify(err));
            }
        });
        //var result = {
        //    "result": "{\"placeId\":1,\"roomId\":3,\"placeName\":\"龙华10kV变电站\"}"
        //};
        //var place = JSON.parse(result.result);

        //if (place.placeId != null && place.roomId != null) {
        //    $scope.PlaceId = place.placeId;
        //    $scope.PlaceName = place.placeName;
        //    $scope.RoomId = place.roomId;
        //    $scope.AddModel.RoomId = place.roomId;
        //    $scope.GetPlaceDepartment($scope.PlaceId, $scope.AddModel);
        //    $http({
        //        method: 'POST',
        //        url: '../CheckForm/GetMyCheckTypeList',
        //        data: { 'PlaceId': $scope.PlaceId }
        //    }).success(function (ret) {
        //        if (ret.Data != null) {
        //            $scope.AddModel.CheckType = ret.Data.Id + '';
        //        }

        //        if ($scope.AddModel.CheckType != null) {
        //            $scope.GetCheckItemList($scope.RoomId, $scope.AddModel.CheckType);
        //        }
        //    })
        //        .error(function (data, status, headers, config) {
        //            if ($scope.AddModel.CheckType != null) {
        //                $scope.GetCheckItemList($scope.RoomId, $scope.AddModel.CheckType);
        //            }
        //        });


        //}
    }

    $scope.MSaveSupInspectionForm = function (status, model, list, filelist) {
        mui.showLoading("正在上传...", "div");
        model.FormStatus = status;
        $http({
            method: 'POST',
            url: '../CheckForm/AddCheckForm',
            data: { 'model': model, 'items': list, 'FileList': filelist }
        })
            .success(function (ret) {
                common.success($scope, null, ret);
                mui.hideLoading();
                if (ret.Code == 100) {
                    mui.alert(ret.Msg, '系统提醒', function () {     
                        location.href = "../CheckForm/MSupervisionInspectionList";
                    });
                }
                else {
                    mui.alert(ret.Msg, '系统异常');
                }
            })
            .error(function (data, status, headers, config) {
                mui.alert("请检查网络");
            });
    }

    $scope.InitSupInspectionListPage = function () {
        $scope.PageIndex = 0;
        mui.init({
            pullRefresh: {
                container: '#pullrefresh',
                down: {
                    style: 'circle',
                    auto: false,//可选,默认false.首次加载自动上拉刷新一次
                    callback: function () {
                        setTimeout(function () {
                            $scope.MGetSupInspection($scope.SearchModel, 1);
                            mui('#pullrefresh').pullRefresh().refresh(true);
                            mui('#pullrefresh').pullRefresh().endPulldownToRefresh();
                        }, 1500);

                    }
                }, up: {
                    auto: true,
                    contentrefresh: '正在加载...',
                    callback: function () {
                        $scope.MGetSupInspection($scope.SearchModel, $scope.PageIndex + 1);
                    },

                }
            }
        });
    }
    $scope.GetSuperviseCheckType = function () {
        $scope.CheckTypeList = [];
        $http({
            method: 'POST',
            url: '../CheckForm/GetSuperviseCheckType'
        })
            .success(function (ret) {
                common.success($scope, null, ret);
                if (ret.Code == 100) {
                    $scope.CheckTypeList = ret.Data;
                    if ($scope.AddModel.CheckType == null) {
                        $scope.AddModel.CheckType = ret.Data[0].Id + '';
                    }

                }
                else {
                    alertify.alert(ret.Msg);
                }
            })
            .error(function (data, status, headers, config) {
                alertify.alert("请检查网络");
            });
    }

    $scope.AddCheckPlace = function (model) {
        model.FormStatus = 0;
        model.CheckTime = $("#datetime").val();
        model.Responsible = model.ResponsibleUserNo;
        model.CheckType = $scope.AddModel.CheckType;
        $http({
            method: 'POST',
            url: '../CheckForm/AddCheckForm',
            data: { 'model': model, 'items': model.CheckOptionList, 'FileList': $scope.FileList, 'Source': 0 }
        })
            .success(function (ret) {
                common.success($scope, null, ret);
                if (ret.Code == 100) {
                    mui.toast(ret.Msg);
                    $scope.PlaceList = [];

                    $http({
                        method: 'POST',
                        url: '../CheckForm/AddFeedBackJoinPlaceCheck',
                        data: { 'FormId': ret.Data, 'FeedBackNo': $scope.AddModel.FeedBackFormNo }
                    })

                    $scope.GetPlaceCheckedList($scope.AddModel.FeedBackFormNo);
                }
                else {
                    mui.toast(ret.Msg);
                }
            })
            .error(function (data, status, headers, config) {
                alertify.alert("请检查网络");
            });
    }
    $scope.GetPlaceCheckedList = function (formno) {
        $http({
            method: 'POST',
            url: '../CheckForm/GetPlaceCheckedList',
            data: { 'FormNo': formno }
        })
            .success(function (ret) {
                common.success($scope, null, ret);
                if (ret.Code == 100) {
                    $scope.PlaceCheckedList = ret.Data;
                    setTimeout(function () {
                        mui.previewImage();
                    }, 2000);
                }
                else {
                    alertify.alert(ret.Msg);
                }
            })
            .error(function (data, status, headers, config) {
                alertify.alert("请检查网络");
            });
    }
    $scope.RemoveCheckPlace = function (model) {
        $scope.PlaceList.splice($scope.PlaceList.indexOf(model), 1);
    }

    $scope.DeletePlaceCheck = function (model) {
        mui.confirm('确认删除该场所检查单？', '系统提醒', ['否', '是'], function (e) {
            if (e.index == 1) {
                $http({
                    method: 'POST',
                    url: '../CheckForm/DeletePlaceCheck',
                    data: { 'FormId': model.FormId, "FormNo": $scope.AddModel.FeedBackFormNo }
                })
                    .success(function (ret) {
                        common.success($scope, null, ret);
                        if (ret.Code == 100) {
                            mui.toast("删除成功！");
                            $scope.GetPlaceCheckedList($scope.AddModel.FeedBackFormNo);
                        }
                        else {
                            mui.toast(ret.Msg);
                        }
                    })
                    .error(function (data, status, headers, config) {
                        alertify.alert("请检查网络");
                    });
            } else {
                //mui.toast("");
            }
        })

    }

    $scope.GetCheckFeedbackDetail = function (id) {
        $scope.AddModel = {};

        $http({
            method: 'POST',
            url: '../CheckForm/GetCheckFeedback',
            data: { 'Id': id }
        })
            .success(function (ret) {
                common.success($scope, null, ret);
                if (ret.Code == 100) {
                    $scope.AddModel = ret.Data;
                    $scope.AddModel.CreateTime = $filter('JSONDate')($scope.AddModel.CreateTime, 'yyyy-MM-dd HH:mm:ss');
                    $scope.AddModel.CheckTime = $filter('JSONDate')($scope.AddModel.CheckTime, 'yyyy-MM-dd');
                    $scope.AddModel.CheckType = ret.Data.CheckType + '';
                    $scope.GetPlaceCheckedList(ret.Data.FeedBackFormNo);
                }
                else {

                }
            })
            .error(function (data, status, headers, config) {
                mui("请检查网络");
            });
    }

    //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
    $scope.InitDatePicker = function (control) {
        (function ($) {
            $.init();
            var btns = $(control);
            btns.each(function (i, btn) {
                btn.addEventListener('tap', function () {
                    var _self = this;
                    if (_self.picker) {
                        _self.picker.show(function (rs) {
                            jQuery(control).val(rs.text);
                            _self.picker.dispose();
                            _self.picker = null;
                        });
                    } else {
                        var optionsJson = this.getAttribute('data-options') || '{}';
                        var options = JSON.parse(optionsJson);
                        var id = this.getAttribute('id');
                        _self.picker = new $.DtPicker(options);
                        _self.picker.show(function (rs) {
                            jQuery(control).val(rs.text);
                            console.log($scope.AddModel);
                            _self.picker.dispose();
                            _self.picker = null;
                        });
                    }
                }, false);
            });
        })(mui);
    }
    $scope.GetNodeMenu = function (node) {
        mui.showLoading("正在加载..", "div");
        var hmenu = sessionStorage.getItem('CheckMenu');
        if (hmenu == null) {
            $http({
                method: 'POST',
                url: '../Account/GetMMenuList',
                data: { 'Node': node }
            })
                .success(function (ret) {
                    mui.hideLoading();
                    common.success($scope, null, ret);
                    if (ret.Code == 100) {
                        $scope.CheckMenuList = ret.Data;
                        sessionStorage.setItem("CheckMenu", JSON.stringify(ret.Data));
                    }
                    else {
                        mui.toast(ret.Msg);
                    }
                })
                .error(function (data, status, headers, config) {
                    mui.toast("请检查网络");
                });
        }
        else {
            $scope.CheckMenuList = JSON.parse(hmenu);
            mui.hideLoading();
        }
    }
    $scope.GetCheckTypeList = function (roomId, placeid) {
        $scope.CheckTypeList = [];
        $http({
            method: 'POST',
            url: '../CheckForm/GetCheckTypeList',
            data: { 'PlaceId': placeid }
        })
            .success(function (ret) {
                common.success($scope, null, ret);
                if (ret.Code == 100) {
                    $scope.CheckTypeList = ret.Data;

                    if ($scope.CheckTypeId != 0) {
                        $scope.GetCheckItemList(roomId, $scope.CheckTypeId);

                        $scope.AddModel.CheckType = $scope.CheckTypeId;
                    }
                    else {
                        $scope.GetCheckItemList(roomId, $scope.CheckTypeList[0].Id);

                        $scope.AddModel.CheckType = $scope.CheckTypeList[0].Id + "";
                    }


                }
                else {
                    alertify.alert(ret.Msg);
                }
            })
            .error(function (data, status, headers, config) {
                alertify.alert("请检查网络");
            });
    }

    $scope.GetAllCheckTypeList = function () {
        $scope.CheckTypeList = [];
        $http({
            method: 'POST',
            url: '../CheckForm/GetAllCheckTypeList'
        })
            .success(function (ret) {
                common.success($scope, null, ret);
                if (ret.Code == 100) {
                    $scope.CheckTypeList = ret.Data;
                }
                else {
                    alertify.alert(ret.Msg);
                }
            })
            .error(function (data, status, headers, config) {
                alertify.alert("请检查网络");
            });
    }

    $scope.GetPlaceDepartment = function (placeid, model) {
        $http({
            method: 'POST',
            url: '../CheckForm/GetCheckPlaceBasicInfo',
            data: { 'PlaceId': placeid }
        })
            .success(function (ret) {
                common.success($scope, null, ret);
                if (ret.Code == 100) {
                    model.Manager = ret.Data.DepartmentManager;
                    model.ResponsibleName = ret.Data.UserName;
                    model.Responsible = ret.Data.UserNo;
                }
                else {
                    alertify.alert(ret.Msg);
                }
            })
            .error(function (data, status, headers, config) {
                alertify.alert("请检查网络");
            });

        $http({
            method: 'POST',
            url: '../CheckForm/GetCheckPlaceDepartmentInfo',
            data: { 'PlaceId': placeid }
        })
            .success(function (ret) {
                common.success($scope, null, ret);
                if (ret.Code == 100) {
                    model.DepartmentId = ret.Data.DepartmentId;
                    model.DepartmentName = ret.Data.DepartmentName;
                    model.Manager = ret.Data.UserName;
                }
                else {
                    alertify.alert(ret.Msg);
                }
            })
            .error(function (data, status, headers, config) {
                alertify.alert("请检查网络");
            });


    }

    $scope.GetCheckItemList = function (id, type) {
        $scope.CheckItemList = [];
        $http({
            method: 'POST',
            url: '../CheckForm/GetCheckOptionList',
            data: { 'RoomId': id, 'TypeId': type }
        })
            .success(function (ret) {
                common.success($scope, null, ret);
                if (ret.Code == 100) {
                    $scope.CheckItemList = ret.Data;

                }
                else {
                    alertify.alert(ret.Msg);
                }
            })
            .error(function (data, status, headers, config) {
                alertify.alert("请检查网络");
            });
    }

    $scope.SaveCheckForm = function (model, list, filelist) {
        model.FormStatus = 0;
        $http({
            method: 'POST',
            url: '../CheckForm/AddCheckForm',
            data: { 'model': model, 'items': list, 'FileList': filelist }
        })
            .success(function (ret) {
                common.success($scope, null, ret);
                if (ret.Code == 100) {
                    alertify.alert(ret.Msg);
                    location.href = "../CheckForm/DailyCheckFormPageList";
                }
                else {
                    alertify.alert(ret.Msg);
                }
            })
            .error(function (data, status, headers, config) {
                alertify.alert("请检查网络");
            });
    }

    $scope.SubmitCheckForm = function (model, list, filelist) {
        model.FormStatus = 1;
        $http({
            method: 'POST',
            url: '../CheckForm/AddCheckForm',
            data: { 'model': model, 'items': list, 'FileList': filelist }
        })
            .success(function (ret) {
                common.success($scope, null, ret);
                if (ret.Code == 100) {
                    if (ret.Data != null) {
                        alertify.alert("检查存在问题项，正在跳转问题登记页面！");
                        setTimeout(function () {
                            location.href = "../HiddenTrouble/HiddenTroubleEdit?FormId=" + ret.Data + "&page=1&pagename=HiddenTroubleRectification&IsCheck=1";
                        }, 3000);
                    }
                    else {
                        alertify.alert(ret.Msg);
                        location.href = "../CheckForm/DailyCheckFormPageList";
                    }
                }
                else {
                    alertify.alert(ret.Msg);
                }
            })
            .error(function (data, status, headers, config) {
                alertify.alert("请检查网络");
            });
    }

    $scope.GetCheckFormPageList = function (model, page) {
        $scope.CheckFormPageList = [];
        $http({
            method: 'POST',
            url: '../CheckForm/GetCheckFormPageList',
            data: { 'model': model },
            params: { 'page': page }
        })
            .success(function (ret) {
                common.success($scope, null, ret);
                if (ret.Code == 100) {
                    $scope.TotalCount = ret.Data.TotalItemCount;
                    $scope.CheckFormPageList = ret.Data.Data;
                }
                else {
                    alertify.alert(ret.Msg);
                }
            })
            .error(function (data, status, headers, config) {
                alertify.alert("请检查网络");
            });
    }

    $scope.GetCheckDetail = function (id) {
        $scope.DeleteFileList = [];
        $scope.FileList = [];
        $scope.CheckDetail = [];
        $http({
            method: 'POST',
            url: '../CheckForm/GetCheckFormDetail',
            data: { 'FormId': id }
        })
            .success(function (ret) {
                common.success($scope, null, ret);
                if (ret.Code == 100) {
                    $scope.CheckDetail = ret.Data;
                    $scope.CheckDetail.CheckTime = $filter('JSONDate')($scope.CheckDetail.CheckTime, 'yyyy-MM-dd');
                    if ($scope.CheckDetail.PlaceId != 0) {
                        $scope.GetPlaceDepartment($scope.CheckDetail.PlaceId, $scope.CheckDetail);
                    }

                    setTimeout(function () {
                        for (var x = 0; x < ret.Data.CheckItemList.length; x++) {
                            var itemid = ret.Data.CheckItemList[x].Id;
                            var boxlist = [0, 1, 2];
                            var filelist = ret.Data.CheckItemList[x].FileList;
                            for (var f = 0; f < filelist.length; f++) {
                                var imagebox = "#imagebox-" + ret.Data.CheckItemList[x].OptionId + "_" + f;
                                var htmlcontent = "<img ng-click='ShowPicture(\"" + filelist[f].FilePath + "\");' src='" + filelist[f].FilePath + "' width='50' height='40'/><a ng-click='DeleteCheckItemImg(\"" + itemid + "\",\"" + filelist[f].FileId + "\",\"" + ret.Data.CheckItemList[x].OptionId + "\",\"" + f + "\");' class = 'removeImage'>×</a>";
                                //htmlcontent += '<a  class="btn btn-primary btn-xs btn-label"><i class="fa fa-arrows-alt"></i>预览</a>';
                                var $html = $compile(htmlcontent)($scope);
                                $(imagebox).html($html);
                                boxlist.splice(0, 1);
                            }

                            for (var i = 0; i < boxlist.length; i++) {
                                var imagebox = "#imagebox-" + ret.Data.CheckItemList[x].OptionId + "_" + boxlist[i];
                                var dragImgUpload = new DragImgUpload(imagebox, {
                                    callback: function (files, optionId, index) {
                                        //回调函数，可以传递给后台等等
                                        var file = files[0];
                                        Upload.upload({
                                            method: 'POST',
                                            url: '../CheckForm/UploadImage',
                                            file: file
                                        })
                                            .success(function (ret) {
                                                if (ret.Code == 100) {
                                                    var fileobj = {};
                                                    fileobj.OptionId = optionId;
                                                    fileobj.FileId = ret.Data;
                                                    fileobj.Index = index;
                                                    for (var z = 0; z < $scope.FileList.length; z++) {
                                                        var f = $scope.FileList[z];
                                                        if (f.OptionId == optionId && f.Index == index) {
                                                            $scope.FileList.splice($.inArray(f, $scope.FileList, 1));
                                                        }
                                                    }
                                                    $scope.FileList.push(fileobj);
                                                    console.log($scope.FileList);

                                                } else
                                                    alertify.alert(ret.Msg);
                                            })
                                            .error(function (data, status, headers, config) {
                                                common.error($scope);
                                                alertify.alert("请检查网络");
                                            })
                                    }
                                }, ret.Data.CheckItemList[x].OptionId, boxlist[i]);
                            }
                        }
                    }, 1000);
                }
                else {
                    alertify.alert(ret.Msg);
                }
            })
            .error(function (data, status, headers, config) {
                alertify.alert("请检查网络");
            });
    }

    $scope.DeleteCheckItemImg = function (itemId, fileId, optionId, index) {
        var obj = {};
        obj.ItemId = itemId;
        obj.FileId = fileId;

        $scope.DeleteFileList.push(obj);
        var imagebox = "#imagebox-" + optionId + "_" + index;
        $(imagebox).html("");
        setTimeout(function () {
            var dragImgUpload = new DragImgUpload(imagebox, {
                callback: function (files, optionId, index) {
                    //回调函数，可以传递给后台等等
                    var file = files[0];
                    Upload.upload({
                        method: 'POST',
                        url: '../CheckForm/UploadImage',
                        file: file
                    })
                        .success(function (ret) {
                            $scope.Submiting = false;
                            if (ret.Code == 100) {
                                var fileobj = {};
                                fileobj.OptionId = optionId;
                                fileobj.FileId = ret.Data;
                                fileobj.Index = index;
                                for (var z = 0; z < $scope.FileList.length; z++) {
                                    var f = $scope.FileList[z];
                                    if (f.OptionId == optionId && f.Index == index) {
                                        $scope.FileList.splice($.inArray(f, $scope.FileList, 1));
                                    }
                                }
                                $scope.FileList.push(fileobj);
                                console.log($scope.FileList);

                            } else
                                alertify.alert(ret.Msg);
                        })
                        .error(function (data, status, headers, config) {
                            common.error($scope);
                            alertify.alert("请检查网络");
                        })
                }
            }, optionId, index);
        }, 100);

    }
    $scope.ShowPicture = function (src) {
        $scope.IsPreview = true;
        $("#imgshow").attr("src", src);
    }
    $scope.ClosePreview = function () {
        $scope.IsPreview = false;
        $("#imgshow").attr("src", "");
    }
    $scope.GetCheckFormDetail = function (id) {
        $scope.CheckDetail = [];
        $http({
            method: 'POST',
            url: '../CheckForm/GetCheckFormDetail',
            data: { 'FormId': id }
        })
            .success(function (ret) {
                common.success($scope, null, ret);
                if (ret.Code == 100) {
                    $scope.CheckDetail = ret.Data;
                    $scope.CheckDetail.CheckTime = $filter('JSONDate')($scope.CheckDetail.CheckTime, 'yyyy-MM-dd');
                    if ($scope.CheckDetail.PlaceId != 0) {
                        $scope.GetPlaceDepartment($scope.CheckDetail.PlaceId, $scope.CheckDetail);
                        console.log($scope.CheckDetail);
                    }
                }
                else {
                    alertify.alert(ret.Msg);
                }
            })
            .error(function (data, status, headers, config) {
                alertify.alert("请检查网络");
            });
    }

    $scope.UpdateCheckFormItem = function (model) {
        $http({
            method: 'POST',
            url: '../CheckForm/UpdateCheckFormItem',
            data: { 'model': model, 'FileList': $scope.FileList, 'DeleteFileList': $scope.DeleteFileList }
        })
            .success(function (ret) {
                common.success($scope, null, ret);
                if (ret.Code == 100) {
                    $scope.AlertBox("修改成功！");
                }
                else {
                    alertify.alert(ret.Msg);
                }
            })
            .error(function (data, status, headers, config) {
                alertify.alert("请检查网络");
            });
    }


    $scope.UpdateCheckFormStatus = function (id, status, model, page) {
        alertify.okBtn("确认")
            .cancelBtn("取消").confirm("确认此操作？", function (ev) {
                ev.preventDefault();
                $http({
                    method: 'POST',
                    url: '../CheckForm/UpdateCheckFormStatus',
                    data: { 'FormId': id, 'Status': status }
                })
                    .success(function (ret) {
                        common.success($scope, null, ret);
                        if (ret.Code == 100) {
                            $scope.AlertBox("操作成功！");
                            $scope.GetCheckFormPageList(model, page);
                        }
                        else {
                            alertify.alert(ret.Msg);
                        }
                    })
                    .error(function (data, status, headers, config) {
                        alertify.alert("请检查网络");
                    });
            }, function (ev) {
                ev.preventDefault();
            });

    }

    $scope.UpdateFormStatus = function (id, status, page) {
        $http({
            method: 'POST',
            url: '../CheckForm/EditCheckForm',
            data: { 'FormId': id, 'Status': status, 'itemmodel': $scope.CheckDetail.CheckItemList, 'AddFileList': $scope.FileList, 'DeleteFileList': $scope.DeleteFileList }
        })
            .success(function (ret) {
                common.success($scope, null, ret);
                if (ret.Code == 100) {
                    if (ret.Data != null) {
                        alertify.alert("检查存在问题项，正在跳转问题登记页面！");
                        setTimeout(function () {
                            location.href = "../HiddenTrouble/HiddenTroubleEdit?FormId=" + ret.Data + "&page=1&pagename=HiddenTroubleRectification&IsCheck=1";
                        }, 3000);
                    }
                    else {
                        alertify.alert(ret.Msg);
                        setTimeout(function () {
                            location.href = "../CheckForm/DailyCheckFormPageList";
                        }, 2000);
                    }
                }
                else {
                    alertify.alert(ret.Msg);
                }
            })
            .error(function (data, status, headers, config) {
                alertify.alert("请检查网络");
            });
    }

    $scope.DeleteCheckForm = function (id, model, page) {
        mui.confirm('确认删除该检查单？', '系统提醒', ['否', '是'], function (e) {
            if (e.index == 1) {
                $http({
                    method: 'POST',
                    url: '../CheckForm/DeleteCheckForm',
                    data: { 'FormId': id }
                })
                    .success(function (ret) {
                        common.success($scope, null, ret);
                        $scope.PageLoading = false;
                        if (ret.Code == 100) {
                            mui.toast(ret.Msg);
                            $("#" + id).remove();
                        }
                        else {
                            mui.toast(ret.Msg);
                        }
                    })
                    .error(function (data, status, headers, config) {
                        alertify.alert("请检查网络");
                    });


            } else {
                //mui.toast("");
            }
        })
    }

    $scope.CheckAll = function (list, v) {
        for (var i = 0; i < list.length; i++) {
            list[i].Result = v;
            $("#Result_" + v + "_" + list[i].OptionId).prop("checked", true);
        }


    }

    $scope.GetParkList = function () {
        $scope.ParkList = [];
        $http({
            method: 'POST',
            url: '../SafetyConfig/GetParkList'
        })
            .success(function (ret) {
                common.success($scope, null, ret);
                if (ret.Code == 100) {
                    $scope.ParkList = ret.Data;
                }
                else {
                    alertify.alert(ret.Msg);
                }
            })
            .error(function (data, status, headers, config) {
                alertify.alert("请检查网络");
            });
    }

    $scope.GetMyParkList = function () {
        $scope.ParkList = [];
        $http({
            method: 'POST',
            url: '../CheckForm/GetParkList'
        })
            .success(function (ret) {
                common.success($scope, null, ret);
                if (ret.Code == 100) {
                    $scope.ParkList = ret.Data;
                }
                else {
                    alertify.alert(ret.Msg);
                }
            })
            .error(function (data, status, headers, config) {
                alertify.alert("请检查网络");
            });
    }

    $scope.GetMyDepartmentList = function () {
        $scope.DepartmentList = [];
        $http({
            method: 'POST',
            url: '../CheckForm/GetMyDepartmentList'
        })
            .success(function (ret) {
                common.success($scope, null, ret);
                if (ret.Code == 100) {
                    $scope.DepartmentList = ret.Data;
                }
                else {
                    alertify.alert(ret.Msg);
                }
            })
            .error(function (data, status, headers, config) {
                alertify.alert("请检查网络");
            });
    }

    $scope.GetMyCheckType = function () {
        $scope.CheckTypeList = [];
        $http({
            method: 'POST',
            url: '../CheckForm/GetMyCheckType'
        })
            .success(function (ret) {
                common.success($scope, null, ret);
                if (ret.Code == 100) {
                    $scope.CheckTypeList = ret.Data;
                }
                else {
                    alertify.alert(ret.Msg);
                }
            })
            .error(function (data, status, headers, config) {
                alertify.alert("请检查网络");
            });
    }
    $scope.GetPlaceList = function (id) {
        $scope.PlaceList = [];
        $http({
            method: 'POST',
            url: '../CheckForm/GetPlaceList',
            data: { "ParkId": id }
        })
            .success(function (ret) {
                common.success($scope, null, ret);
                if (ret.Code == 100) {
                    $scope.PlaceList = ret.Data;
                }
                else {
                    alertify.alert(ret.Msg);
                }
            })
            .error(function (data, status, headers, config) {
                alertify.alert("请检查网络");
            });
    }

    $scope.GetBuildingList = function (id) {
        $scope.BuildingList = [];
        $http({
            method: 'POST',
            url: '../SafetyConfig/GetBuildingList',
            data: { 'ParkId': id }
        })
            .success(function (ret) {
                common.success($scope, null, ret);
                if (ret.Code == 100) {
                    $scope.BuildingList = ret.Data;
                }
                else {
                    alertify.alert(ret.Msg);
                }
            })
            .error(function (data, status, headers, config) {
                alertify.alert("请检查网络");
            });
    }

    $scope.GetFloorList = function (id) {
        $scope.FloorList = [];
        $http({
            method: 'POST',
            url: '../SafetyConfig/GetFloorList',
            data: { 'BuildingId': id }
        })
            .success(function (ret) {
                common.success($scope, null, ret);
                if (ret.Code == 100) {
                    $scope.FloorList = ret.Data;
                }
                else {
                    alertify.alert(ret.Msg);
                }
            })
            .error(function (data, status, headers, config) {
                alertify.alert("请检查网络");
            });
    }

    $scope.GetRoomList = function (id) {
        $scope.RoomList = [];
        $http({
            method: 'POST',
            url: '../SafetyConfig/GetRoomList',
            data: { 'FloorId': id }
        })
            .success(function (ret) {
                common.success($scope, null, ret);
                if (ret.Code == 100) {
                    $scope.RoomList = ret.Data;
                }
                else {
                    alertify.alert(ret.Msg);
                }
            })
            .error(function (data, status, headers, config) {
                alertify.alert("请检查网络");
            });
    }

    $scope.GetDepartmentList = function (id) {
        $scope.DepartmentList = [];
        $http({
            method: 'POST',
            url: '../CheckForm/GetDepartmentList'
        })
            .success(function (ret) {
                common.success($scope, null, ret);
                if (ret.Code == 100) {
                    $scope.DepartmentList = ret.Data;
                }
                else {
                    alertify.alert(ret.Msg);
                }
            })
            .error(function (data, status, headers, config) {
                alertify.alert("请检查网络");
            });
    }
    $scope.GetPlaceTypeList = function () {
        $scope.PlaceTypeList = [];
        $http({
            method: 'POST',
            url: '../CheckForm/GetPlaceTypeList'
        })
            .success(function (ret) {
                common.success($scope, null, ret);
                if (ret.Code == 100) {
                    $scope.PlaceTypeList = ret.Data;
                }
                else {
                    alertify.alert(ret.Msg);
                }
            })
            .error(function (data, status, headers, config) {
                alertify.alert("请检查网络");
            });
    }
    //专项检查 开始
    $scope.GetCheckOptionList = function (CheckContent) {
        $scope.CheckOptionList = [];
        $http({
            method: 'POST',
            url: '../CheckForm/GetSpecialCheckOptions',
            data: { 'CheckContent': CheckContent, "Olist": $scope.SelectedOption }
        })
            .success(function (ret) {
                common.success($scope, null, ret);
                if (ret.Code == 100) {
                    $scope.CheckOptionList = ret.Data;
                }
                else {
                    alertify.alert(ret.Msg);
                }
            })
            .error(function (data, status, headers, config) {
                alertify.alert("请检查网络");
            });
    }

    $scope.InitStep = function () {
        $scope.slist = ["草稿", "下发", "完成"];
        $scope.MyStep = $("#step");
        $scope.MyStep.step({
            index: -1,
            time: 500,
            title: $scope.slist
        });
    }

    $scope.InitSpecialCheckStep = function (status) {
        $("#step").html("");
        $scope.slist = ["暂存", "待审核", "完成"];
        $scope.MyStep = $("#step");
        if (status != null) {
            $scope.MyStep.step({
                index: status,
                time: 500,
                title: $scope.slist
            });
        }
        else {
            $scope.MyStep.step({
                index: -1,
                time: 500,
                title: $scope.slist
            });
        }

    }
    $scope.AddSpeicalCheckOption = function (checkcontent) {
        $http({
            method: 'POST',
            url: '../CheckForm/AddSpecialCheckOptions',
            data: { 'CheckContent': checkcontent }
        })
            .success(function (ret) {
                common.success($scope, null, ret);
                if (ret.Code == 100) {
                    $scope.AlertBox("添加成功！");
                    $scope.GetCheckOptionList(checkcontent);
                }
                else {
                    alertify.alert(ret.Msg);
                }
            })
            .error(function (data, status, headers, config) {
                alertify.alert("请检查网络");
            });
    }

    $scope.SelectCheckOption = function (model) {
        $scope.SelectedOption.push(model);
        $scope.GetCheckOptionList($scope.CheckOption.CheckCotent);
    }

    $scope.InArray = function (list, obj) {
        for (var i = 0; i < list.length; i++) {
            if (list[i].Id == obj.Id) {
                return true;
            }
        }
        return false;
    }

    $scope.RemoveCheckOption = function (list, x) {
        for (var i = 0; i < list.length; i++) {
            if (list[i].Id == x.Id) {
                list.splice(i, 1);
            }
        }
    }

    $scope.SelectAll = function (obj, name) {
        if ($("#Department_All").prop("checked")) {
            var list = $('[name="' + name + '"]');
            for (var i = 0; i < list.length; i++) {
                $(list[i]).prop("checked", true);
            }
        }
        else {
            var list = $('[name="' + name + '"]');
            for (var i = 0; i < list.length; i++) {
                $(list[i]).prop("checked", false);
            }
        }

    }

    $scope.SaveCheckTask = function (AddModel, status) {
        AddModel.Status = status;
        var list = $("#SelectedCheckList li");
        var checklist = [];
        var department = [];
        for (var i = 0; i < list.length; i++) {
            var id = list[i].id;
            var isvalue = $("#Result_1_" + id).prop("checked");
            var obj = {};
            obj.OptionId = id;
            obj.SortBy = i + 1;
            obj.IsValue = isvalue;
            checklist.push(obj);
        }

        var deplist = $('[name=DepartmentSelected]');
        for (var i = 0; i < deplist.length; i++) {
            if ($(deplist[i]).prop("checked")) {
                department.push(deplist[i].id);
            }
        }

        var files = document.getElementById("taskfile").files;
        $scope.Submiting = true;
        $scope.LoadingMsg = "正在提交,请稍后...";
        Upload.upload({
            method: 'POST',
            url: '../CheckForm/AddSpecialCheckTask',
            data: { 'model': AddModel, 'departmentList': department, 'optionList': checklist },
            file: files
        })
            .success(function (ret) {
                $scope.Submiting = false;
                if (ret.Code == 100) {
                    alertify.alert(ret.Msg);
                    setTimeout(function () {
                        window.location.href = "SpecialCheckTaskPageList?page=1";
                    }, 2000);
                } else
                    alertify.alert(ret.Msg);
            })
            .error(function (data, status, headers, config) {
                common.error($scope);
                $scope.PageLoading = false;
                alertify.alert("请检查网络");
            })

    }

    $scope.GetSpecialTaskPageList = function (model, page) {
        $scope.SpecialTaskList = [];
        $http({
            method: 'POST',
            url: '../CheckForm/GetSpecialTaskPageList',
            data: { 'model': model },
            params: { 'page': page }
        })
            .success(function (ret) {
                common.success($scope, null, ret);
                if (ret.Code == 100) {
                    $scope.TotalCount = ret.Data.TotalItemCount;
                    $scope.SpecialTaskList = ret.Data.Data;
                }
                else {
                    alertify.alert(ret.Msg);
                }
            })
            .error(function (data, status, headers, config) {
                alertify.alert("请检查网络");
            });
    }

    $scope.ShowCheckDepartmentList = function (list) {
        $scope.CheckDepartmentList = list;
    }

    $scope.ShowCheckOptionList = function (list) {
        $scope.CheckOptionList = list;
    }

    $scope.GetSpecialTask = function (Id) {
        $scope.SpecialTaskModel = {};
        $http({
            method: 'POST',
            url: '../CheckForm/GetSpecialCheckTask',
            data: { 'Id': Id }
        })
            .success(function (ret) {
                common.success($scope, null, ret);
                if (ret.Code == 100) {
                    $scope.SpecialTaskModel = ret.Data;
                    $scope.SpecialTaskModel.CreateTime = $filter('JSONDate')($scope.SpecialTaskModel.CreateTime, 'yyyy-MM-dd HH:mm:ss');
                    $scope.SpecialTaskModel.StartTime = $filter('JSONDate')($scope.SpecialTaskModel.StartTime, 'yyyy-MM-dd');
                    $scope.SpecialTaskModel.EndTime = $filter('JSONDate')($scope.SpecialTaskModel.EndTime, 'yyyy-MM-dd');
                    for (var i = 0; i < $scope.SpecialTaskModel.CheckOptionList.length; i++) {
                        var m = $scope.SpecialTaskModel.CheckOptionList[i];
                        var obj = {};
                        obj.Id = m.OptionId;
                        obj.CheckContent = m.CheckContent;
                        obj.IsValue = m.IsValue;
                        $scope.SelectedOption.push(obj);
                    }
                    setTimeout(function () {
                        for (var i = 0; i < $scope.SpecialTaskModel.DepartmentList.length; i++) {
                            $("#" + $scope.SpecialTaskModel.DepartmentList[i]).prop("checked", true);
                        }

                    }, 500);


                }
                else {
                    alertify.alert(ret.Msg);
                }
            })
            .error(function (data, status, headers, config) {
                alertify.alert("请检查网络");
            });
    }

    $scope.DeleteSpecialCheckTaskFile = function (id, filelist) {
        alertify.okBtn("确认")
            .cancelBtn("取消").confirm("确认此操作？", function (ev) {
                ev.preventDefault();
                $scope.PageLoading = true;
                $http({
                    method: 'POST',
                    url: '../CheckForm/DeleteSpecialCheckTaskFile',
                    data: { 'Id': id }
                })
                    .success(function (ret) {
                        common.success($scope, null, ret);
                        $scope.PageLoading = false;
                        if (ret.Code == 100) {
                            $scope.AlertBox("删除成功！");
                            for (var i = 0; i < filelist.length; i++) {
                                if (filelist[i].FileId == id) {
                                    filelist.splice(i, 1);
                                }
                            }
                        }
                        else {
                            alertify.alert(ret.Msg);
                        }
                    })
                    .error(function (data, status, headers, config) {
                        alertify.alert("请检查网络");
                    });
            }, function (ev) {
                ev.preventDefault();
            });

    }

    $scope.EditCheckTask = function (AddModel, status, page) {
        AddModel.Status = status;
        var list = $("#SelectedCheckList li");
        var checklist = [];
        var department = [];
        for (var i = 0; i < list.length; i++) {
            var id = list[i].id;
            var isvalue = $("#Result_1_" + id).prop("checked");
            var obj = {};
            obj.OptionId = id;
            obj.SortBy = i + 1;
            obj.IsValue = isvalue;
            checklist.push(obj);
        }

        var deplist = $('[name=DepartmentSelected]');
        for (var i = 0; i < deplist.length; i++) {
            if ($(deplist[i]).prop("checked")) {
                department.push(deplist[i].id);
            }
        }

        var files = document.getElementById("taskfile").files;
        $scope.Submiting = true;
        $scope.LoadingMsg = "正在提交,请稍后...";
        Upload.upload({
            method: 'POST',
            url: '../CheckForm/EditSpecialCheckTask',
            data: { 'model': AddModel, 'departmentList': department, 'optionList': checklist },
            file: files
        })
            .success(function (ret) {
                $scope.Submiting = false;
                if (ret.Code == 100) {
                    alertify.alert(ret.Msg);
                    setTimeout(function () {
                        window.location.href = "SpecialCheckTaskPageList?page=" + page;
                    }, 3000);
                } else
                    alertify.alert(ret.Msg);
            })
            .error(function (data, status, headers, config) {
                common.error($scope);
                $scope.PageLoading = false;
                alertify.alert("请检查网络");
            })

    }

    $scope.GetMySpecialCheckTaskPageList = function (model, page) {
        $scope.SpecialTaskList = [];
        $http({
            method: 'POST',
            url: '../CheckForm/GetMySpecialCheckTaskPageList',
            data: { 'model': model },
            params: { 'page': page }
        })
            .success(function (ret) {
                common.success($scope, null, ret);
                if (ret.Code == 100) {
                    $scope.TotalCount = ret.Data.TotalItemCount;
                    $scope.SpecialTaskList = ret.Data.Data;
                }
                else {
                    alertify.alert(ret.Msg);
                }
            })
            .error(function (data, status, headers, config) {
                alertify.alert("请检查网络");
            });
    }

    $scope.GetMyPlaceList = function () {
        $scope.MyPlaceList = [];
        $http({
            method: 'POST',
            url: '../CheckForm/GetMyPlaceList'
        })
            .success(function (ret) {
                common.success($scope, null, ret);
                if (ret.Code == 100) {
                    $scope.MyPlaceList = ret.Data;
                }
                else {
                    alertify.alert(ret.Msg);
                }
            })
            .error(function (data, status, headers, config) {
                alertify.alert("请检查网络");
            });
    }

    $scope.GetPlaceDepartmentManager = function (id) {
        $scope.Manager = {};
        $http({
            method: 'POST',
            url: '../CheckForm/GetPlaceDepartmentManager',
            data: { 'PlaceId': id }
        })
            .success(function (ret) {
                common.success($scope, null, ret);
                if (ret.Code == 100) {
                    $scope.Manager = ret.Data;
                }
                else {
                    alertify.alert(ret.Msg);
                }
            })
            .error(function (data, status, headers, config) {
                alertify.alert("请检查网络");
            });
    }
	$scope.InitLxImgUpload_SC = function (id, optionId, index,taskId) {
        try {
            var id = id + optionId + "_" + index;
            lx.media.chooseImage({
                count: 1,
                sourceType: ["album", "camera"],
                quality: 'high',
                success: function (res) {
                    var filelist = res.tempFiles;
                    var img = document.getElementById(id);
                    img.src = filelist[0].base64;
                    var file = $scope.base64ToFile(filelist[0].base64, filelist[0].name);
                    Upload.upload({
                        method: 'POST',
                        url: '../CheckForm/UploadSpcialCheckImage',
						data: { "TaskId": taskId },
                        file: file
                    }).success(function (ret) {
                        common.success($scope, null, ret);
                        if (ret.Code == 100) {
							
                            var fileobj = {};
                            fileobj.OptionId = optionId;
                            fileobj.FileId = ret.Data;
                            fileobj.Index = index;
                            for (var z = 0; z < $scope.FileList.length; z++) {
                                var f = $scope.FileList[z];
                                if (f.OptionId == optionId && f.Index == index) {
                                    $scope.FileList.splice($.inArray(f, $scope.FileList, 1));
                                }
                            }
                            $scope.FileList.push(fileobj);
                        }
                        else {
                            mui.toast(ret.Msg);
                        }
                    })
                }
            });
        } catch (error) {
            mui.toast(error);
        }
    }
    $scope.GetTaskCheckOption = function (Id) {
        $scope.TaskOptionList = [];
        $http({
            method: 'POST',
            url: '../CheckForm/GetTaskCheckOption',
            data: { 'TaskId': Id }
        })
            .success(function (ret) {
                common.success($scope, null, ret);
                if (ret.Code == 100) {
                    $scope.TaskOptionList = ret.Data;

                   
                }
                else {
                    alertify.alert(ret.Msg);
                }
            })
            .error(function (data, status, headers, config) {
                alertify.alert("请检查网络");
            });
    }

    $scope.SaveSpecialCheckForm = function (model, list, filelist, status, pagename) {
        model.Status = status;
        var plist = [];
        var placelist = $('[name=PlaceSelected]');
        for (var i = 0; i < placelist.length; i++) {
            if ($(placelist[i]).prop("checked")) {
                plist.push(placelist[i].id);
            }
        }
        $http({
            method: 'POST',
            url: '../CheckForm/AddSpecialCheckForm',
            data: { 'model': model, 'PlaceList': plist, 'ItemList': list, 'FileList': filelist }
        })
            .success(function (ret) {
                common.success($scope, null, ret);
                if (ret.Code == 100) {
                    mui.toast(ret.Msg);
                    setTimeout(function () {
                        if (pagename != null && pagename != "") {
                            location.href = pagename;
                        }
                        else {
                            location.href = "../CheckForm/MSpecialCheckTaskList";
                        }

                    }, 3000);

                }
                else {
                    mui.toast(ret.Msg);
                }
            })
            .error(function (data, status, headers, config) {
                alertify.alert("请检查网络");
            });
    }


    $scope.GeCompleteSpecialCheckRecordList = function (model, page) {
        $scope.SpecialCheckList = [];
        $http({
            method: 'POST',
            url: '../CheckForm/GeCompleteSpecialCheckRecordList',
            data: { 'model': model },
            params: { 'page': page }
        })
            .success(function (ret) {
                common.success($scope, null, ret);
                if (ret.Code == 100) {
                    $scope.TotalCount = ret.Data.TotalItemCount;
                    $scope.SpecialCheckList = ret.Data.Data;
                }
                else {
                    alertify.alert(ret.Msg);
                }
            })
            .error(function (data, status, headers, config) {
                alertify.alert("请检查网络");
            });
    }

    $scope.UpdateSpecialCheckFormStatus = function (formid, status, url, page) {
        $http({
            method: 'POST',
            url: '../CheckForm/UpdateSpecialCheckStatus',
            data: { 'FormId': formid, 'Status': status }
        })
            .success(function (ret) {
                common.success($scope, null, ret);
                if (ret.Code == 100) {
                    alertify.alert(ret.Msg);
                    location.href = url + "?page=" + page;
                }
                else {
                    alertify.alert(ret.Msg);
                }
            })
            .error(function (data, status, headers, config) {
                alertify.alert("请检查网络");
            });
    }

    $scope.ApproveSpecialCheckForm = function (formid, status, taskId, pagename) {
        $scope.LogModel.FormId = formid;
        if (status == 0)
            $scope.LogModel.Result = false;
        else
            $scope.LogModel.Result = true;
        $http({
            method: 'POST',
            url: '../CheckForm/UpdateSpecialCheckStatus',
            data: { 'FormId': formid, 'Status': status }
        })
            .success(function (ret) {
                common.success($scope, null, ret);
                if (ret.Code == 100) {
                    mui.toast("操作成功！");
                    $http({
                        method: 'POST',
                        url: '../CheckForm/AddApproveLog',
                        data: { 'model': $scope.LogModel }
                    })
                    setTimeout(function () {
                        if (pagename != null && pagename != "") {
                            location.href = pagename;
                        }
                        else {
                            location.href = "../CheckForm/MSpecialCheckRecordList?TaskId=" + taskId;
                        }
                    }, 3000);
                }
                else {
                    mui.toast(ret.Msg);
                }
            })
            .error(function (data, status, headers, config) {
                mui.toast("请检查网络");
            });



    }

    $scope.GetSpecialCheckFormDetail = function (id) {
        $scope.LogModel = {};
        $scope.currentid = id;
        $scope.SpecialCheckDetail = {};
        $http({
            method: 'POST',
            url: '../CheckForm/GetSpecialCheckFormDetail',
            data: { 'FormId': id }
        })
            .success(function (ret) {
                common.success($scope, null, ret);
                if (ret.Code == 100) {
                    $scope.SpecialCheckDetail = ret.Data;
                }
                else {
                    alertify.alert(ret.Msg);
                }
            })
            .error(function (data, status, headers, config) {
                alertify.alert("请检查网络");
            });
    }
    $scope.DeleteSpecialCheckItemImg = function (itemId, fileId, optionId, index) {
        var obj = {};
        obj.ItemId = itemId;
        obj.FileId = fileId;

        $scope.DeleteFileList.push(obj);
        var imagebox = "#imagebox-" + optionId + "_" + index;
        $(imagebox).html("");
        setTimeout(function () {
            var dragImgUpload = new DragImgUpload(imagebox, {
                callback: function (files, optionId, index) {
                    //回调函数，可以传递给后台等等
                    var file = files[0];
                    Upload.upload({
                        method: 'POST',
                        url: '../CheckForm/UploadSpcialCheckImage',
                        file: file
                    })
                        .success(function (ret) {
                            $scope.Submiting = false;
                            if (ret.Code == 100) {
                                var fileobj = {};
                                fileobj.OptionId = optionId;
                                fileobj.FileId = ret.Data;
                                fileobj.Index = index;
                                for (var z = 0; z < $scope.FileList.length; z++) {
                                    var f = $scope.FileList[z];
                                    if (f.OptionId == optionId && f.Index == index) {
                                        $scope.FileList.splice($.inArray(f, $scope.FileList, 1));
                                    }
                                }
                                $scope.FileList.push(fileobj);
                                console.log($scope.FileList);

                            } else
                                alertify.alert(ret.Msg);
                        })
                        .error(function (data, status, headers, config) {
                            common.error($scope);
                            alertify.alert("请检查网络");
                        })
                }
            }, optionId, index);
        }, 100);
    }
    $scope.GetSpecialCheckFormEdit = function (id) {
        $scope.DeleteFileList = [];
        $scope.FileList = [];
        $scope.SpecialCheckDetail = {};
        $http({
            method: 'POST',
            url: '../CheckForm/GetSpecialCheckFormDetail',
            data: { 'FormId': id }
        })
            .success(function (ret) {
                common.success($scope, null, ret);
                if (ret.Code == 100) {
                    $scope.SpecialCheckDetail = ret.Data;
                    $scope.SpecialCheckDetail.CheckTime = $filter('JSONDate')($scope.SpecialCheckDetail.CheckTime, 'yyyy-MM-dd');
                    for (var i = 0; i < $scope.SpecialCheckDetail.PlaceList.length; i++) {
                        $("#" + $scope.SpecialCheckDetail.PlaceList[i]).prop("checked", true);
                    }

                    setTimeout(function () {
                        for (var x = 0; x < ret.Data.CheckItemList.length; x++) {
                            var itemid = ret.Data.CheckItemList[x].Id;
                            var boxlist = [0, 1, 2];
                            var filelist = ret.Data.CheckItemList[x].FileList;
                            for (var f = 0; f < filelist.length; f++) {
                                var imagebox = "#imagebox-" + ret.Data.CheckItemList[x].OptionId + "_" + f;
                                var htmlcontent = "<img ng-click='ShowPicture(\"" + filelist[f].FilePath + "\");' src='" + filelist[f].FilePath + "' width='50' height='40'/><a ng-click='DeleteSpecialCheckItemImg(\"" + itemid + "\",\"" + filelist[f].FileId + "\",\"" + ret.Data.CheckItemList[x].OptionId + "\",\"" + f + "\");' class = 'removeImage'>×</a>";
                                //htmlcontent += '<a  class="btn btn-primary btn-xs btn-label"><i class="fa fa-arrows-alt"></i>预览</a>';
                                var $html = $compile(htmlcontent)($scope);
                                $(imagebox).html($html);
                                boxlist.splice(0, 1);
                            }

                            for (var i = 0; i < boxlist.length; i++) {
                                var imagebox = "#imagebox-" + ret.Data.CheckItemList[x].OptionId + "_" + boxlist[i];
                                var dragImgUpload = new DragImgUpload(imagebox, {
                                    callback: function (files, optionId, index) {
                                        //回调函数，可以传递给后台等等
                                        var file = files[0];
                                        Upload.upload({
                                            method: 'POST',
                                            url: '../CheckForm/UploadSpcialCheckImage',
                                            file: file
                                        })
                                            .success(function (ret) {
                                                if (ret.Code == 100) {
                                                    var fileobj = {};
                                                    fileobj.OptionId = optionId;
                                                    fileobj.FileId = ret.Data;
                                                    fileobj.Index = index;
                                                    for (var z = 0; z < $scope.FileList.length; z++) {
                                                        var f = $scope.FileList[z];
                                                        if (f.OptionId == optionId && f.Index == index) {
                                                            $scope.FileList.splice($.inArray(f, $scope.FileList, 1));
                                                        }
                                                    }
                                                    $scope.FileList.push(fileobj);
                                                    console.log($scope.FileList);

                                                } else
                                                    alertify.alert(ret.Msg);
                                            })
                                            .error(function (data, status, headers, config) {
                                                common.error($scope);
                                                alertify.alert("请检查网络");
                                            })
                                    }
                                }, ret.Data.CheckItemList[x].OptionId, boxlist[i]);
                            }
                        }
                    }, 1000);
                }
                else {
                    alertify.alert(ret.Msg);
                }
            })
            .error(function (data, status, headers, config) {
                alertify.alert("请检查网络");
            });
    }
    $scope.EditSpecialCheckForm = function (id, status, page, name, taskId) {
        var plist = [];
        var placelist = $('[name=PlaceSelected]');
        for (var i = 0; i < placelist.length; i++) {
            if ($(placelist[i]).prop("checked")) {
                plist.push(placelist[i].id);
            }
        }
        $http({
            method: 'POST',
            url: '../CheckForm/EditSpecialCheckForm',
            data: { 'FormId': id, 'PlaceList': plist, 'Status': status, 'ItemList': $scope.SpecialCheckDetail.CheckItemList, 'FileList': $scope.FileList, 'DeleteFileList': $scope.DeleteFileList }
        })
            .success(function (ret) {
                common.success($scope, null, ret);
                if (ret.Code == 100) {
                    alertify.alert(ret.Msg);
                    setTimeout(function () {
                        location.href = "../CheckForm/SpecialCheckRecordList?page=" + page + "&TaskId=" + taskId + "&TaskName=" + name;
                    }, 2000);
                }
                else {
                    alertify.alert(ret.Msg);
                }
            })
            .error(function (data, status, headers, config) {
                alertify.alert("请检查网络");
            });
    }
    $scope.GetApproveLogList = function (id) {
        $scope.ApproveLogList = [];
        $http({
            method: 'POST',
            url: '../CheckForm/GetApproveLog',
            data: { 'FormId': id }
        })
            .success(function (ret) {
                common.success($scope, null, ret);
                if (ret.Code == 100) {
                    $scope.ApproveLogList = ret.Data;
                }
                else {
                    alertify.alert(ret.Msg);
                }
            })
            .error(function (data, status, headers, config) {
                alertify.alert("请检查网络");
            });
    }

    $scope.DeleteSpecialCheckForm = function (id, model, page) {
        alertify.okBtn("确认")
            .cancelBtn("取消").confirm("确认此操作？", function (ev) {
                ev.preventDefault();
                $scope.PageLoading = true;
                $http({
                    method: 'POST',
                    url: '../CheckForm/DeleteSpecialCheckForm',
                    data: { 'FormId': id }
                })
                    .success(function (ret) {
                        common.success($scope, null, ret);
                        $scope.PageLoading = false;
                        if (ret.Code == 100) {
                            alertify.alert(ret.Msg);
                            $scope.GetMySpecialCheckRecordList(model, page);
                        }
                        else {
                            alertify.alert(ret.Msg);
                        }
                    })
                    .error(function (data, status, headers, config) {
                        alertify.alert("请检查网络");
                    });
            }, function (ev) {
                ev.preventDefault();
            });

    }
    $scope.MSaveCheckForm = function (status, model, list, filelist, pagename) {
        mui.showLoading("正在上传...", "div");
        model.FormStatus = status;
        $http({
            method: 'POST',
            url: '../CheckForm/AddCheckForm',
            data: { 'model': model, 'items': list, 'FileList': filelist }
        })
            .success(function (ret) {
                common.success($scope, null, ret);
                mui.hideLoading();
                if (ret.Code == 100) {
                    if (ret.Data != null) {
                        mui.alert('操作成功。检查项存在异常，跳转问题登记', '系统提醒', function () {
                            location.href = "../HiddenTrouble/MHiddenTroubleEdit?IsCheck=1&FormId=" + ret.Data;
                        });
                    }
                    else {
                        mui.alert(ret.Msg, '系统提醒', function () {
                            if (pagename != null && pagename != "") {
                                if (pagename == "../Home/MPlaceWork") {
                                    location.href = '../Home/MPlaceWork?PlaceId=' + model.PlaceId + "&RoomId=" + model.RoomId + "&PlaceName=" + model.PlaceName;
                                }
                                else {
                                    location.href = pagename;
                                }
                            }
                            else {
                                location.href = "../CheckForm/MDailyCheckFormPageList";
                            }
                        });
                    }
                }
                else {
                    mui.alert(ret.Msg, '系统异常');
                }
            })
            .error(function (data, status, headers, config) {
                mui.alert("请检查网络");
            });
    }
    $scope.MGetSupInspection = function (model, page) {
        if (page == 1) {
            $scope.CheckFormPageList = [];
        }
        $scope.PageIndex = page;
        if ($("#starttime").val() != "") {
            model.StartTime = $("#starttime").val();
        }
        if ($("#endtime").val() != "") {
            model.EndTime = $("#endtime").val();
        }
        $http({
            method: 'POST',
            url: '../CheckForm/GetSupervisionInspectionList',
            data: { 'model': model },
            params: { 'page': page }
        })
            .success(function (ret) {
                common.success($scope, null, ret);

                if (ret.Code == 100) {
                    $scope.TotalCount = ret.Data.TotalItemCount;
                    for (var i = 0; i < ret.Data.Data.length; i++) {
                        $scope.CheckFormPageList.push(ret.Data.Data[i]);
                    }
                    if (ret.Data.Data.length == 0) {
                        mui('#pullrefresh').pullRefresh().endPullupToRefresh(true);
                    }
                    else {
                        mui('#pullrefresh').pullRefresh().endPullupToRefresh(false);
                    }
                }
                else {
                    alertify.alert(ret.Msg);
                }
            })
            .error(function (data, status, headers, config) {
                alertify.alert("请检查网络");
            });
    }

    $scope.MGetCheckFormPageList = function (model, page) {
        if (page == 1) {
            $scope.CheckFormPageList = [];
        }
        $scope.PageIndex = page;
        if ($("#starttime").val() != "") {
            model.StartTime = $("#starttime").val();
        }
        if ($("#endtime").val() != "") {
            model.EndTime = $("#endtime").val();
        }

        $http({
            method: 'POST',
            url: '../CheckForm/GetPlaceCheckReport',
            data: { 'model': model, 'RoomId': model.RoomId }
        })
            .success(function (ret) {
                common.success($scope, null, ret);

                if (ret.Code == 100) {
                    var myChart = echarts.init(document.getElementById('checktypechart'));

                    var datalist = ret.Data;
                    var option = {
                        tooltip: {
                            trigger: 'item'
                        },
                        legend: {
                            show: false,
                            orient: 'vertical',
                            left: 'left'
                        },
                        toolbox: {
                            show: false,
                            orient: 'vertical',
                            left: 'right',
                            top: 'center',
                            feature: {
                                saveAsImage: { show: true }
                            }
                        },
                        series: [
                            {
                                name: '',
                                type: 'pie',
                                radius: ['40%', '70%'],
                                label: {
                                    alignTo: 'labelLine',
                                    formatter: '{name|{b}}{c}次',
                                    minMargin: 5,
                                    edgeDistance: 3,
                                    lineHeight: 15,
                                    rich: {
                                        time: {
                                            fontSize: 10,
                                            color: '#999'
                                        }
                                    }
                                },
                                labelLine: {
                                    show: true
                                },
                                data: datalist,
                                itemStyle: {
                                    normal: {
                                        color: function (params) {
                                            var colorList = [
                                                '#00E5AB', '#FFCC33', '#0E5DA6', '#FF6666', '#0E5DA6', '#1177DC', '#FF6666'
                                            ];
                                            return colorList[params.dataIndex]
                                        }
                                    }
                                }
                            }
                        ]
                    };
                    myChart.setOption(option);
                }
                else {
                    mui.toast(ret.Msg);
                }
            })
            .error(function (data, status, headers, config) {
                alertify.alert("请检查网络");
            });

        $http({
            method: 'POST',
            url: '../CheckForm/GetCheckFormPageList',
            data: { 'model': model },
            params: { 'page': page }
        })
            .success(function (ret) {
                common.success($scope, null, ret);

                if (ret.Code == 100) {
                    $scope.TotalCount = ret.Data.TotalItemCount;
                    // $scope.CheckFormPageList = ret.Data.Data;
                    for (var i = 0; i < ret.Data.Data.length; i++) {
                        $scope.CheckFormPageList.push(ret.Data.Data[i]);
                    }
                    if (ret.Data.Data.length == 0) {
                        mui('#pullrefresh').pullRefresh().endPullupToRefresh(true);
                    }
                    else {
                        mui('#pullrefresh').pullRefresh().endPullupToRefresh(false);
                    }
                }
                else {
                    alertify.alert(ret.Msg);
                }
            })
            .error(function (data, status, headers, config) {
                alertify.alert("请检查网络");
            });
    }
    $scope.InitMyCheckFormListPage = function () {
        $scope.PageIndex = 1;
        mui.init({
            pullRefresh: {
                container: '#pullrefresh',
                down: {
                    style: 'circle',
                    auto: false,//可选,默认false.首次加载自动上拉刷新一次
                    callback: function () {
                        setTimeout(function () {
                            $scope.MGetCheckFormPageList($scope.SearchModel, 1);
                            mui('#pullrefresh').pullRefresh().refresh(true);
                            mui('#pullrefresh').pullRefresh().endPulldownToRefresh();
                        }, 1500);

                    }
                }, up: {
                    auto: false,
                    contentrefresh: '正在加载...',
                    callback: function () {
                        $scope.MGetCheckFormPageList($scope.SearchModel, $scope.PageIndex + 1);
                    },

                }
            }
        });
    }

    $scope.InitMySpecialCheckTaskList = function () {
        $scope.PageIndex = 1;
        mui.init({
            pullRefresh: {
                container: '#pullrefresh',
                down: {
                    style: 'circle',
                    auto: true,//可选,默认false.首次加载自动上拉刷新一次
                    callback: function () {
                        setTimeout(function () {
                            $scope.MGetSpecialCheckTaskList($scope.SearchModel, 1);
                            mui('#pullrefresh').pullRefresh().refresh(true);
                            mui('#pullrefresh').pullRefresh().endPulldownToRefresh();
                        }, 1500);

                    }
                }, up: {
                    auto: false,
                    contentrefresh: '正在加载...',
                    callback: function () {
                        $scope.MGetSpecialCheckTaskList($scope.SearchModel, $scope.PageIndex + 1);
                    },

                }
            }
        });
    }

    $scope.MGetSpecialCheckTaskList = function (model, page) {
        if (page == 1) {
            $scope.CheckTaskList = [];
        }
        $scope.PageIndex = page;
        $http({
            method: 'POST',
            url: '../CheckForm/GetMySpecialCheckTaskPageList',
            data: { 'model': model },
            params: { 'page': page }
        })
            .success(function (ret) {
                common.success($scope, null, ret);
                if (ret.Code == 100) {
                    $scope.TotalCount = ret.Data.TotalItemCount;
                    for (var i = 0; i < ret.Data.Data.length; i++) {
                        $scope.CheckTaskList.push(ret.Data.Data[i]);
                    }
                    if (ret.Data.Data.length == 0) {
                        mui('#pullrefresh').pullRefresh().endPullupToRefresh(true);
                    }
                    else {
                        mui('#pullrefresh').pullRefresh().endPullupToRefresh(false);
                    }
                }
                else {
                    alertify.alert(ret.Msg);
                }
            })
            .error(function (data, status, headers, config) {
                alertify.alert("请检查网络");
            });
    }

    $scope.GetMySpecialCheckRecordList = function (model, page) {
        if (page == 1) {
            $scope.SpecialCheckRecordList = [];
        }
        $scope.PageIndex = page;
        model.TaskId = $scope.TaskId;
        $http({
            method: 'POST',
            url: '../CheckForm/GetMySpecialCheckRecordList',
            data: { 'model': model },
            params: { 'page': page }
        })
            .success(function (ret) {
                mui('#pullrefresh').pullRefresh().endPulldownToRefresh();
                common.success($scope, null, ret);
                if (ret.Code == 100) {
                    $scope.TotalCount = ret.Data.TotalItemCount;
                    for (var i = 0; i < ret.Data.Data.length; i++) {
                        $scope.SpecialCheckRecordList.push(ret.Data.Data[i]);
                    }
                    if (ret.Data.Data.length == 0) {
                        mui('#pullrefresh').pullRefresh().endPullupToRefresh(true);
                    }
                    else {
                        mui('#pullrefresh').pullRefresh().endPullupToRefresh(false);
                    }
                }
                else {
                    alertify.alert(ret.Msg);
                }
            })
            .error(function (data, status, headers, config) {
                alertify.alert("请检查网络");
            });
    }

    $scope.InitMySpecialCheckRecordList = function () {
        $scope.PageIndex = 1;
        mui.init({
            pullRefresh: {
                container: '#pullrefresh',
                down: {
                    style: 'circle',
                    auto: true,//可选,默认false.首次加载自动上拉刷新一次
                    callback: function () {
                        setTimeout(function () {
                            $scope.GetMySpecialCheckRecordList($scope.SearchModel, 1);
                            mui('#pullrefresh').pullRefresh().refresh(true);
                            mui('#pullrefresh').pullRefresh().endPulldownToRefresh();
                        }, 1500);

                    }
                }, up: {
                    auto: false,
                    contentrefresh: '正在加载...',
                    callback: function () {
                        $scope.GetMySpecialCheckRecordList($scope.SearchModel, $scope.PageIndex + 1);
                    },

                }
            }
        });
    }
    //专项检查 结束

    //监督检查
    $scope.InitDatePicker = function (control) {
        (function ($) {
            $.init();
            var btns = $(control);
            btns.each(function (i, btn) {
                btn.addEventListener('tap', function () {
                    var _self = this;
                    if (_self.picker) {
                        _self.picker.show(function (rs) {
                            jQuery(control).val(rs.text);
                            _self.picker.dispose();
                            _self.picker = null;
                        });
                    } else {
                        var optionsJson = this.getAttribute('data-options') || '{}';
                        var options = JSON.parse(optionsJson);
                        var id = this.getAttribute('id');
                        _self.picker = new $.DtPicker(options);
                        _self.picker.show(function (rs) {
                            jQuery(control).val(rs.text);
                            console.log($scope.AddModel);
                            _self.picker.dispose();
                            _self.picker = null;
                        });
                    }
                }, false);
            });
        })(mui);
    }

    $scope.SaveCheckFeedback = function (model) {
        $scope.Loading = true;
        model.CheckTime = $("#datetime").val();

        $http({
            method: 'POST',
            url: '../CheckForm/CheckFeedbackAdd',
            data: { 'model': model }
        })
            .success(function (ret) {
                $scope.Loading = false;
                common.success($scope, null, ret);
                if (ret.Code == 100) {
                    mui.alert(ret.Msg, '系统提醒', function () {
                        location.href = "../CheckForm/MCheckFeedbackList";
                    });
                }
                else {
                    mui.alert(ret.Msg, '系统提醒', function () {

                    });
                }
            })
            .error(function (data, status, headers, config) {
                alertify.alert("请检查网络");
            });
    }

    $scope.MGetFeedbackPageList = function (model, page) {
        if (page == 1) {
            $scope.FeedbackList = [];
        }
        $scope.PageIndex = page;
        $http({
            method: 'POST',
            url: '../CheckForm/CheckFeedbackPageList',
            data: { 'model': model },
            params: { 'page': page }
        })
            .success(function (ret) {
                common.success($scope, null, ret);
                if (ret.Code == 100) {
                    $scope.TotalCount = ret.Data.TotalItemCount;
                    for (var i = 0; i < ret.Data.Data.length; i++) {
                        $scope.FeedbackList.push(ret.Data.Data[i]);
                    }
                    if (ret.Data.Data.length == 0) {
                        mui('#pullrefresh').pullRefresh().endPullupToRefresh(true);
                    }
                    else {
                        mui('#pullrefresh').pullRefresh().endPullupToRefresh(false);
                    }
                }
                else {
                    mui.toast(ret.Msg);
                }
            })
            .error(function (data, status, headers, config) {
                mui.toast("请检查网络");
            });
    }

    $scope.InitCheckFeedbackList = function () {
        $scope.PageIndex = 1;
        mui.init({
            pullRefresh: {
                container: '#pullrefresh',
                down: {
                    style: 'circle',
                    auto: true,//可选,默认false.首次加载自动上拉刷新一次
                    callback: function () {
                        setTimeout(function () {
                            $scope.MGetFeedbackPageList($scope.SearchModel, 1);
                            mui('#pullrefresh').pullRefresh().refresh(true);
                            mui('#pullrefresh').pullRefresh().endPulldownToRefresh();
                        }, 1500);

                    }
                }, up: {
                    auto: false,
                    contentrefresh: '正在加载...',
                    callback: function () {
                        $scope.MGetFeedbackPageList($scope.SearchModel, $scope.PageIndex + 1);
                    },

                }
            }
        });
    }




    $scope.EditCheckFeedback = function (model) {
        $scope.Loading = true;
        model.CheckTime = $("#datetime").val();

        $http({
            method: 'POST',
            url: '../CheckForm/CheckFeedbackEdit',
            data: { 'model': model }
        })
            .success(function (ret) {
                $scope.Loading = false;
                common.success($scope, null, ret);
                if (ret.Code == 100) {
                    mui.alert(ret.Msg, '系统提醒', function () {
                        location.href = "../CheckForm/MCheckFeedbackList";
                    });
                }
                else {
                    mui.alert(ret.Msg, '系统提醒', function () {

                    });
                }
            })
            .error(function (data, status, headers, config) {
                alertify.alert("请检查网络");
            });
    }



    $scope.DeleteCheckFeedback = function (id, model, page) {
        mui.confirm('确认删除该检查单？', '系统提醒', ['否', '是'], function (e) {
            if (e.index == 1) {
                $http({
                    method: 'POST',
                    url: '../CheckForm/DeleteCheckFeedback',
                    data: { 'Id': id }
                })
                    .success(function (ret) {
                        common.success($scope, null, ret);
                        $scope.PageLoading = false;
                        if (ret.Code == 100) {
                            mui.toast(ret.Msg);
                            $("#list_" + id).remove();
                        }
                        else {
                            mui.toast(ret.Msg);
                        }
                    })
                    .error(function (data, status, headers, config) {
                        alertify.alert("请检查网络");
                    });
            } else {
                //mui.toast("");
            }
        })
    }

    $scope.GetDailyCheckStatus = function (model) {
        $scope.CheckStatusList = {};
        if ($("#starttime").val() != "") {
            model.StartTime = $("#starttime").val();
        }
        if ($("#endtime").val() != "") {
            model.EndTime = $("#endtime").val();
        }
        console.log(model);
        $http({
            method: 'POST',
            url: '../CheckForm/GetDailyCheckStatus',
            data: { 'model': model }
        })
            .success(function (ret) {
                $scope.Loading = false;
                common.success($scope, null, ret);
                if (ret.Code == 100) {
                    var datalist = [];
                    $scope.CheckStatusList = ret.Data;
                    var daily = {
                        "name": "日检", "value": ret.Data.DailyCount
                    };
                    datalist.push(daily);

                    var weekly = {
                        "name": "周检", "value": ret.Data.WeeklyCount
                    };
                    datalist.push(weekly);

                    var monthly = {
                        "name": "月检", "value": ret.Data.MonthlyCount
                    };
                    datalist.push(monthly);

                    var exceptioncount = {
                        "name": "异常", "value": ret.Data.ExcepetionCount
                    };
                    datalist.push(exceptioncount);

                    var myChart = echarts.init(document.getElementById('checkchart'));


                    var option = {
                        tooltip: {
                            trigger: 'item'
                        },
                        legend: {
                            show: false,
                            orient: 'vertical',
                            left: 'left'
                        },
                        toolbox: {
                            show: false,
                            orient: 'vertical',
                            left: 'right',
                            top: 'center',
                            feature: {
                                saveAsImage: { show: true }
                            }
                        },
                        series: [
                            {
                                name: '',
                                type: 'pie',
                                radius: ['40%', '70%'],
                                label: {
                                    alignTo: 'labelLine',
                                    formatter: '{name|{b}}{c}次',
                                    minMargin: 5,
                                    edgeDistance: 3,
                                    lineHeight: 15,
                                    rich: {
                                        time: {
                                            fontSize: 10,
                                            color: '#999'
                                        }
                                    }
                                },
                                labelLine: {
                                    show: true
                                },
                                data: datalist,
                                itemStyle: {
                                    normal: {
                                        color: function (params) {
                                            var colorList = [
                                                '#00E5AB', '#FFCC33', '#0E5DA6', '#FF6666', '#0E5DA6', '#1177DC', '#FF6666'
                                            ];
                                            return colorList[params.dataIndex]
                                        }
                                    }
                                }
                            }
                        ]
                    };
                    myChart.setOption(option);
                    var dlist = ret.Data.DetailList;
                    if (model.Type == 1) {
                        document.getElementById('depchart').style.height = "1000px";
                    }
                    else if (model.Type == 2) {
                        document.getElementById('depchart').style.height = "400px";
                    }
                    else if (model.Type == 3) {
                        document.getElementById('depchart').style.height = "400px";
                    }
                    setTimeout(function () {
                        var myChart2 = echarts.init(document.getElementById('depchart'));
                        var namelist = [];
                        var dailylist = [];
                        var weeklylist = [];
                        var monthlylist = [];
                        var exlist = [];
                        for (var i = 0; i < dlist.length; i++) {
                            if (model.Type == 1) {
                                namelist.push(dlist[i].DepName);
                            }
                            else if (model.Type == 2) {
                                namelist.push(dlist[i].TypeName);
                            }
                            else if (model.Type == 3) {
                                namelist.push(dlist[i].ParkName);
                            }
                            dailylist.push(dlist[i].DailyCount);
                            weeklylist.push(dlist[i].WeeklyCount);
                            monthlylist.push(dlist[i].MonthlyCount);
                            exlist.push(dlist[i].ExcepetionCount);
                        }
                        var option2 = {
                            tooltip: {
                                trigger: 'axis',
                                axisPointer: {
                                    // Use axis to trigger tooltip
                                    type: 'shadow' // 'shadow' as default; can also be 'line' or 'shadow'
                                }
                            },
                            legend: { show: false },
                            grid: {
                                left: '3%',
                                right: '4%',
                                bottom: '3%',
                                containLabel: true
                            },
                            xAxis: {
                                type: 'value',
                                splitline: false,
                                minInterval: 1
                            },
                            yAxis: {
                                type: 'category',

                                data: namelist//['Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sun']
                            },
                            series: [
                                {
                                    name: '日检',
                                    type: 'bar',
                                    stack: 'total',
                                    label: {
                                        show: false
                                    },
                                    itemStyle: {
                                        color: '#33CCCC',
                                    },
                                    emphasis: {
                                        focus: 'series'
                                    },
                                    data: dailylist
                                },
                                {
                                    name: '周检',
                                    type: 'bar',
                                    stack: 'total',
                                    label: {
                                        show: false
                                    },
                                    itemStyle: {
                                        color: '#FFCC33',
                                    },
                                    emphasis: {
                                        focus: 'series'
                                    },
                                    data: weeklylist
                                },
                                {
                                    name: '月检',
                                    type: 'bar',
                                    stack: 'total',
                                    label: {
                                        show: false
                                    },
                                    itemStyle: {
                                        color: '#0E5DA6',
                                    },
                                    emphasis: {
                                        focus: 'series'
                                    },
                                    data: monthlylist
                                },
                                {
                                    name: '异常',
                                    type: 'bar',
                                    stack: 'exception',
                                    label: {
                                        show: false
                                    },
                                    itemStyle: {
                                        color: '#FF6666',
                                    },
                                    emphasis: {
                                        focus: 'series'
                                    },
                                    data: exlist
                                }
                            ]
                        };
                        myChart2.resize();
                        myChart2.setOption(option2);
                    }, 1000);
                }
                else {

                }
            })
            .error(function (data, status, headers, config) {
                alertify.alert("请检查网络");
            });
    }


    //监督检查 结束
});


app.filter('GetStatus', function () { //可以注入依赖
    return function (text) {
        if (text == '0')
            return "禁用";
        else if (text == '1')
            return "启用";

    }
});

app.filter('GetBoolStr', function () { //可以注入依赖
    return function (text) {
        if (text)
            return "启用";
        else
            return "禁用";

    }
});

app.filter('GetSpecialCheckStatus', function () { //可以注入依赖
    return function (text) {
        if (text == 0)
            return "保存";
        else if (text == 1)
            return "已下发";
    }
});
app.filter('GetWeekDay', function () {
    return function (enddate) {
        var endDate = new Date(enddate);
        var beginDate = new Date(endDate.getFullYear(), 0, 1);
        //星期从0-6,0代表星期天，6代表星期六
        var endWeek = endDate.getDay();
        if (endWeek == 0) endWeek = 7;
        var beginWeek = beginDate.getDay();
        if (beginWeek == 0) beginWeek = 7;
        //计算两个日期的天数差
        var millisDiff = endDate.getTime() - beginDate.getTime();
        var dayDiff = Math.floor((millisDiff + (beginWeek - endWeek) * (24 * 60 * 60 * 1000)) / 86400000);
        return Math.ceil(dayDiff / 7) + 1;
    }

});